package com.atao.baokede.mapper;

import com.atao.baokede.pojo.DetailOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ItemOrderDetailMapper {
    /**
     * 添加订单详情
     * @param detailOrder
     */
    @Insert("insert into order_detail(order_id,item_id,item_name,merchant_id,num,price,spec,status,create_time,update_time) " +
            "values(#{orderId},#{itemId},#{itemName},#{merchantId},#{num},#{price},#{spec},0,now(),now())")
    void addOrderDetail(DetailOrder detailOrder);

    /**
     * 批量添加订单详情
     * @param detailOrders
     */
    void addBatchOrderDetail(List<DetailOrder> detailOrders);

    /**
     * 根据订单id查询订单详情
     * @param orderId
     * @return
     */
    @Select("select * from order_detail where order_id = #{orderId}")
    DetailOrder getItemDetail(Long orderId);

    /**
     * 根据订单id查询订单详情
     * @param orderId
     * @return
     */
    @Select("select * from order_detail where order_id = #{orderId}")
    List<DetailOrder> getItemDetails(Long orderId);

    /**
     * 根据商品id列表查询订单id（订单号大概率会重复，只要取一次值）
     * @param itemIds
     * @return
     */
    List<Long> findOrderIdsByItemIds(List<Long> itemIds);


    /**
     * 根据商户id查询订单
     * @param merchantId
     * @param status
     * @param orderId
     * @param name
     * @return
     */
    List<DetailOrder> findOrderIdsByMerchantId(Long merchantId,Integer status, String orderId, String name);
}
